package com.crm.system.service.impl.csd.followManager;

import com.crm.common.model.DhPageInfo;
import com.crm.model.qo.csd.followManager.ClueFollowQO;
import com.crm.model.vo.csd.followManager.ClueFollowVO;
import com.crm.service.csd.followManager.CsdClueFollowDbService;
import com.crm.system.service.csd.followManager.CsdClueFollowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yincuimei
 * @Date 2021/11/15 10:37
 */
@Service
public class CsdClueFollowServiceImpl implements CsdClueFollowService {
    @Autowired
    private CsdClueFollowDbService clueFollowDbService;

    /**
     *(客服部)跟进管理-》跟进记录列表
     * @param clueFollowQO  --查询条件
     * @param pageIndex/pageSize --页码/分页大小
     * @param sortName/sortOrder --排序字段/排序规则(ASC/DESC)
     * @author yincuimei
     * @return
     */
    @Override
    public DhPageInfo<ClueFollowVO> selectClueFollowVOList(ClueFollowQO clueFollowQO, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append("t.create_tm ").append(sortOrder);//创建时间
                }
                break;
                case "followTm": {
                    order.append("t.follow_tm ").append(sortOrder);//跟进时间
                }
                break;
                default:
                    break;
            }
        }
        List<ClueFollowVO> voList = clueFollowDbService.selectClueFollowVOList(clueFollowQO, order.toString());
        PageInfo<ClueFollowVO> pageInfo = new PageInfo<>(voList);
        return new DhPageInfo<ClueFollowVO>(pageInfo, voList);
    }
}
